package com.sk.compiler.info.autowire;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class AutowireInfo {

    private List<FieldInfo> fieldInfos;
    private List<MethodInfo> methodInfos;
    private Set<String> packages;

    public AutowireInfo() {
        fieldInfos=new ArrayList<>();
        methodInfos=new ArrayList<>();
        packages=new HashSet<>();
    }

    public List<FieldInfo> getFieldInfos() {
        return fieldInfos;
    }

    public List<MethodInfo> getMethodInfos() {
        return methodInfos;
    }

    public Set<String> getPackages() {
        return packages;
    }

    public void addFieldInfo(String field, String key, String fullClass) {
        String clazz=addPackageAndGetName(fullClass);
        fieldInfos.add(new FieldInfo(field,key,clazz));
    }

    private String addPackageAndGetName(String fullClass) {
        packages.add(fullClass);
        return fullClass.substring(fullClass.lastIndexOf('.')+1);
    }

    public void addMethodInfo(MethodInfo methodInfo) {
        packages.addAll(methodInfo.getPackages());
        methodInfos.add(methodInfo);
    }

}